home *** CD-ROM | disk | FTP | other *** search
- Path: newshub.ccs.yorku.ca!news
- From: "Shahed A. Quazi" <yu106781@yorku.ca>
- Newsgroups: comp.lang.c
- Subject: PlLS HELP with my "SUCCESSOR" and "REMOVE" function !!
- Date: Sun, 07 Apr 1996 01:22:55 -0800
- Organization: York University, Canada
- Message-ID: <3167896F.31D9@yorku.ca>
- NNTP-Posting-Host: pugsly13.slip.yorku.ca
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Hi,
- The following are the two functions I wrote, for a B-TREE program,
- where the user should be able to insert, search and delete key from
- the tree.
-
- Now, my problem is, the deletion is not working and I would really
- appreciate if someone could tell me what am I doing wrong in the
- following two functions.
-
- ....
- typedef struct {
- short keycount; /* number of keys in page */
- int key[MAXKEYS]; /* the actual keys */
- short child[MAXKEYS+1]; /* ptrs to RRNs of descendants */
- } BTPAGE;
- ..............
- ....................
-
- /*===============================================================*
- This function replaces the key "page.key[pos]" with its
- immediate successor in the B-TREE, and then returns RRN (Relative
- Record Number)of the duplicate of this successor residing in the leaf
- page.
- *==============================================================*/
- short SUCCESSOR (short found_rrn, short pos)
- {
- short rrn_succ;
- BTPAGE page;
- BTPAGE ch_page;
-
- btread (found_rrn, &page);
- rrn_succ = page.child[pos];
-
- while ((btread(rrn_succ, &ch_page)) && (ch_page.child[0]!= NIL))
-
- rrn_succ = ch_page.child[0];
-
-
- btread (rrn_succ, &ch_page); /*read the page containing */
- /* immediate successor. */
- if (ch_page.keycount <= MINKEYS) /* if successor page has */
- return (-1); /* less then MIN keys, then*/
- else{ /* return -1. */
- page.key[pos] = ch_page.key[1];
-
- btwrite(found_rrn, &page); /*writes back to the disk.*/
-
- return (rrn_succ);} /*otherwise, swap the key */
- } /*end function */ /* with successor. */
-
- /*==============================================================*
- Delets the key from a leaf page .
- Here "page" contains the key, "rrn_page" is RRN of this page
- and "pos" is the position of the key.
- *=============================================================*/
- void REMOVE_KEY(BTPAGE page, short rrn_page, short pos){
-
- short i;
- for (i = pos+1; i <= page.keycount; i++)
- page.key[i-1] = page.key[i];
-
- (page.keycount)--;
- btwrite(rrn_page, &page); /* write back the page to disk. */
- } /* end function */
-
-
- thanks in advance,
- shahed
-